<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>搜索新闻</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../default/css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../default/css/index.css" />
		<style type="text/css">
			.mui-bar-nav.mui-bar .mui-icon span {
				font-weight: 500;
				font-size: 14px;
				color: #ffdb28;
			}
			.mui-bar .mui-btn-link{
				color: #ffdb28;
			}
			.mui-search .mui-placeholder{
				line-height: initial;
			}
			body{
				background-color: #fff;
			}
			.mui-content{
				background-color: #fff;
			}
			.news-hot-list{
				margin-top: 20px;
			}
			.news-hot-list .mui-inline{
				margin-top: 20px;
			}
			.news-hot-list .mui-inline span{
				font-size: 14px;
				color: #8F8F94;
			}
			span{
				font-family: charcoal;
			}
			.mui-inline:nth-child(1) b{
				color: #FF0000;
			}
			.mui-inline:nth-child(2) b{
				color: #EC971F;
			}
			.mui-inline:nth-child(3) b{
				color: #ffdb28;

			}

            /*新闻排版*/
            .mui-table-view .mui-media-object {
                max-width: initial;
                width: 100px;
                height: 70px;
                border-radius: 5px;
            }

            .meta-info {
                position: absolute;
                left: 15px;
                right: 15px;
                bottom: 8px;
                color: #8f8f94;
            }

            .meta-info .author,
            .meta-info .time {
                display: inline-block;
            }

            .meta-info .time {
                margin-left: 10px;
            }

            .mui-table-view:before,
            .mui-table-view:after {
                height: 0;
            }

            .mui-content>.mui-table-view:first-child {
                margin-top: 1px;
            }
            #pullrefresh{
                display: none;
            }
            .mui-table-view-chevron .mui-table-view-cell{
                padding-right: 15px;
            }
		</style>
	</head>
	<body>

		<header class="mui-bar mui-bar-nav">
			<button type="button" class="mui-left mui-action-back mui-btn  mui-btn-link mui-btn-nav mui-pull-left">
				<span class="mui-icon mui-icon-left-nav"></span>
			</button>
			<div class="mui-col-xs-8 mui-inline">
				<div class="mui-input-row mui-search">
					<input type="search" class="mui-input-clear" id="search-news" placeholder="输入新闻标题">
				</div>
			</div>

			<a class="mui-icon mui-icon-search mui-pull-right" id="search-news-btn"><span>搜索</span></a>
		</header>



        <div id="pullrefresh" class="mui-content mui-scroll-wrapper">
            <div class="mui-scroll">
                <!--数据列表-->
                <ul class="mui-table-view mui-table-view-chevron"></ul>
            </div>
        </div>
        <div class="mui-content hotspot-news">
            <div class="mui-row">
                <div class="exclusive-task-box">
                    <!--<div class="mui-table">
                        <span class="mui-h5">大家都在搜</span>
                    </div>
                    <div class="mui-table news-hot-list">
                        <div class="mui-col-xs-6 mui-col-sm-6 mui-inline">
                            <b>1.</b>
                            <span>5G网络强势来袭</span>
                        </div>
                        <div class="mui-col-xs-6 mui-col-sm-6 mui-inline">
                            <b>2.</b>
                            <span>5G网络强势来袭</span>
                        </div>
                        <div class="mui-col-xs-6 mui-col-sm-6 mui-inline">
                            <b>3.</b>
                            <span>5G网络强势来袭</span>
                        </div>
                        <div class="mui-col-xs-6 mui-col-sm-6 mui-inline">
                            <b>4.</b>
                            <span>5G网络强势来袭</span>
                        </div>
                        <div class="mui-col-xs-6 mui-col-sm-6 mui-inline">
                            <b>5.</b>
                            <span>5G网络强势来袭</span>
                        </div>
                        <div class="mui-col-xs-6 mui-col-sm-6 mui-inline">
                            <b>6.</b>
                            <span>5G网络强势来袭</span>
                        </div>
                        <div class="mui-col-xs-6 mui-col-sm-6 mui-inline">
                            <b>7.</b>
                            <span>5G网络强势来袭</span>
                        </div>
                        <div class="mui-col-xs-6 mui-col-sm-6 mui-inline">
                            <b>8.</b>
                            <span>测试</span>
                        </div>
                    </div>-->
                </div>
            </div>

		</div>

        <script src="../default/js/jquery-2.14.js" type="text/javascript" charset="utf-8"></script>
        <script src="../default/js/mui.min.js" type="text/javascript" charset="utf-8"></script>
        <script src="../default/js/cookie.js"></script>
        <script src="../default/js/code.js" type="text/javascript" charset="utf-8"></script>
        <script src="../default/js/index.js" type="text/javascript" charset="utf-8"></script>
        <script src="../default/js/public.js"></script>
        <script src="../default/js/mui.lazyload.js"></script>
        <script src="../default/js/mui.lazyload.img.js"></script>
        <script>


            mui.init({
                pullRefresh: {
                    container: '#pullrefresh',
                    up: {
                        contentrefresh: '正在加载...',
                        callback: pullupRefresh
                    }
                }
            });



            mui(".exclusive-task-box .mui-table").on('tap', 'span', function () {
                var title = $(this).html();
                $("input[type=search]").val(title);
                $(".mui-table-view-chevron").html('');
                startingNumber=0;
                setTimeout(function () {
                    searchnews(title);
                },100)
            });

            $("#search-news").on('keypress', function(e) {
                var keycode = e.keyCode;
                //获取搜索框的值
                var title = $(this).val();
                if (keycode == '13') {
                    e.preventDefault();
                    //请求搜索接口
                    if (title == '') {
                        mui.toast('请输入搜索内容');
                    } else {
                        $(".mui-table-view-chevron").html('');
                        startingNumber=0;
                        setTimeout(function () {
                            searchnews(title);
                        },300)
                    }
                }
            });

            mui("header").on('tap','#search-news-btn',function () {
                var title = $("#search-news").val();
                startingNumber=0;
                $(".mui-table-view-chevron").html('');
                setTimeout(function () {
                    searchnews(title);
                },100)
            });


            // 这里是下拉触发的东西
            function pullupRefresh() {
                var title = $("#search-news").val();
                pageNumber++;
                setTimeout(function () {
                    searchnews(title);
                },100)
            };

            // 设置加载中的默认图片
            (function ($) {
                $(document).imageLazyload({
                    placeholder: 'https://srhub.oss-cn-hangzhou.aliyuncs.com/zq-news/images/loading.gif'
                });
            })(mui);



            var pageNumber = 0;
            var pageSize = 10;
            // ajax地址

            function searchnews(title) {

                $.ajax({
                    url:website+'/NewsController/fuzzyNewsQuery',
                    type:'post',
                    data:{
                        pageNumber:pageNumber,
                        pageSize:pageSize,
                        title:title
                    },
                    success:function (data) {
                        $(".hotspot-news").hide();
                        $("#pullrefresh").show();
                        console.log(pageNumber);
                        console.log(data);
                        var html = '';
                        data.rows.forEach(function (value) {
                            html+='<li class="mui-table-view-cell">\n' +
                                '                            <img class="mui-media-object mui-pull-right" src="'+value.encryptedName+'">\n' +
                                '                            <div class="mui-media-body">\n' +
                                '                                <div class="mui-ellipsis-2">'+value.title+'</div>\n' +
                                '                            </div>\n' +
                                '                            <div class="meta-info">\n' +
                                '                                <div class="author">'+value.authorName+'</div>\n' +
                                '                                <div class="time">'+value.writingTime+'</div>\n' +
                                '                            </div>\n' +
                                '                        </li>'
                        });
                        if(data.rows.length == 0){
                            mui.toast('暂无更多数据')
                            html='<li class="mui-table-view-cell mui-text-center">暂无更多数据</li>';
                            $(".mui-table-view-chevron").append(html);
                            mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                        }else if (data.rows.length < pageSize) {
                            console.log(data.rows.length);
                            $(".mui-table-view-chevron").append(html);
                            mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
                        }else {
                            $(".mui-table-view-chevron").append(html);
                        }

                        console.log(data);
                    },error:function () {
                        mui.showLoading("发生错误,返回首页..","div");
                        setTimeout(function () {
                            window.location.href = 'http://newst.whilte.com/index.html';
                        },1000)
                    }
                })
                

            }

            $(function () {
                // 自动获取焦点
                setTimeout("$('input[type=search]').focus()",500);

            });




		</script>
	</body>
</html>
